package com.aspose.cells;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;

class zarv {
   public static HashMap a = new HashMap();

   static String a(zcfl var0, String var1) {
      if (var0.e() != null) {
         zcfh var2 = var0.e();

         for(int var3 = 0; var3 < var2.getCount(); ++var3) {
            zcfg var4 = var2.a(var3);
            if (com.aspose.cells.b.a.zv.b(var4.i(), var1)) {
               return var4.d();
            }
         }
      }

      return "";
   }

   public static void a() {
      a.clear();
   }

   public static void a(zcfl var0, String[] var1, String var2) {
      var1[0] = var1[0] + "<" + var0.i();
      if (var0.b("xmlns") != null && !a.containsKey(var0.b("xmlns"))) {
         var1[0] = var1[0] + " xmlns=\"" + var0.b("xmlns") + "\"";
         String var3 = var0.b("xmlns");
         if (var3 != null) {
            a.put(var3, 0);
         }
      } else if (var2 != null && !a.containsKey(var2)) {
         var1[0] = var1[0] + " xmlns=\"" + var2 + "\"";
         a.put(var2, 0);
      }

      if (var0.e().getCount() > 0) {
         ArrayList var9 = new ArrayList();
         HashMap var4 = new HashMap();
         zcfg var5 = null;

         String var8;
         for(int var6 = 0; var6 < var0.e().getCount(); ++var6) {
            var5 = var0.e().a(var6);
            char var7 = var5.i().charAt(0);
            var8 = var5.i();
            if (var7 < 'a') {
               var8 = "z" + var8;
            }

            var4.put(var8, var5.i());
            var9.add(var8);
         }

         Collections.sort(var9);
         String var13 = "";

         for(int var14 = 0; var14 < var9.size(); ++var14) {
            var13 = (String)var9.get(var14);
            var8 = (String)var4.get(var13);
            var5 = var0.e().a(var8);
            if (var5.i().startsWith("xmlns")) {
               if (var5.h != null && !a.containsKey(var5.h)) {
                  var1[0] = var1[0] + " " + var5.i() + "=\"" + var5.h + "\"";
                  a.put(var5.h, 0);
               }
            } else {
               var1[0] = var1[0] + " " + var5.i() + "=\"" + var5.h + "\"";
            }
         }
      }

      var1[0] = var1[0] + ">";
      zcfs var10 = var0.j();

      for(int var11 = 0; var11 < var10.a(); ++var11) {
         zcfq var12 = var10.a(var11);
         if (var12.e == 3) {
            var1[0] = var1[0] + ((zcfv)var12).h;
         } else {
            a((zcfl)var12, var1, var2);
         }
      }

      var1[0] = var1[0] + "</" + var0.i() + ">";
   }

   static void a(String var0, String[] var1) {
      zcfk var2 = new zcfk();

      try {
         var2.a("<?xml version=\"1.0\" encoding=\"UTF-8\"?><B xmlns=\"http://www.w3.org/2000/09/xmldsig#\">" + var0 + "</B>", false);
      } catch (Exception var4) {
         ;
      }

      zcfl var3 = (zcfl)var2.j().a(0).k();
      a(var3, var1, "http://www.w3.org/2000/09/xmldsig#");
   }

   static void a(String var0, String[] var1, com.aspose.cells.a.f.zi var2) throws Exception {
      zcfk var3 = new zcfk();
      var3.a("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Fix xmlns:mdssi=\"http://schemas.openxmlformats.org/package/2006/digital-signature\">" + var0 + "</Fix>", false);
      zcfl var4 = var3.f();
      a(var4, var1, var2);
   }

   static void a(zcfl var0, String[] var1, com.aspose.cells.a.f.zi var2) throws Exception {
      ArrayList var3 = new ArrayList();
      zcfs var4 = var0.e("mdssi:RelationshipReference");

      for(int var5 = 0; var5 < var4.a(); ++var5) {
         zcfl var6 = (zcfl)var4.a(var5);
         com.aspose.cells.b.a.a.ze.a(var3, (Object)a(var6, "SourceId"));
      }

      Collections.sort(var3);
      zars var14 = new zars("Relationships", "");
      com.aspose.cells.b.a.a.ze.a(var14.b, (Object)(new zakr("xmlns", "http://schemas.openxmlformats.org/package/2006/relationships")));
      String var15 = ((zcfl)var0.k()).e().a("URI").d();
      var15 = var15.substring(0, 0 + var15.indexOf(63));
      com.aspose.cells.a.f.zh var7 = var2.a(com.aspose.cells.b.a.zv.a(var15, '/'));
      if (var7 != null) {
         zcfk var8 = new zcfk();
         var8.a(var2.a(var7));
         Iterator var9 = var3.iterator();

         while(var9.hasNext()) {
            String var10 = (String)var9.next();
            Iterator var11 = var8.f().j().iterator();

            while(var11.hasNext()) {
               zcfl var12 = (zcfl)var11.next();
               if (com.aspose.cells.b.a.zv.b(var12.b("Id"), var10)) {
                  zars var13 = new zars("Relationship", "");
                  com.aspose.cells.b.a.a.ze.a(var13.b, (Object)(new zakr("Id", var10)));
                  com.aspose.cells.b.a.a.ze.a(var13.b, (Object)(new zakr("Target", var12.b("Target"))));
                  com.aspose.cells.b.a.a.ze.a(var13.b, (Object)(new zakr("TargetMode", "Internal")));
                  com.aspose.cells.b.a.a.ze.a(var13.b, (Object)(new zakr("Type", var12.b("Type"))));
                  var14.a((zart)var13);
               }
            }
         }

         var14.a(var1);
      }
   }

   public static String a(zcfl var0) {
      String var1 = "";
      var1 = var1 + "<SignedInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\">";
      var1 = var1 + "<CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"></CanonicalizationMethod>";
      var1 = var1 + "<SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"></SignatureMethod>";
      zcfs var2 = var0.j();

      for(int var3 = 0; var3 < var2.a(); ++var3) {
         zcfl var4 = (zcfl)var2.a(var3);
         if (var4.i().startsWith("Reference")) {
            var1 = var1 + "<Reference Type=\"" + a(var4, "Type") + "\" URI=\"" + a(var4, "URI") + "\">";
            var1 = var1 + "<DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"></DigestMethod><DigestValue>" + var4.g("DigestValue").d() + "</DigestValue>";
            var1 = var1 + "</Reference>";
         }
      }

      var1 = var1 + "</SignedInfo>";
      return var1;
   }
}
